package logic

import (
	"context"

	"go-weixin/app/music/musicrpc/internal/domain"
	"go-weixin/app/music/musicrpc/internal/svc"
	"go-weixin/app/music/musicrpc/pb/proto/music"

	"github.com/zeromicro/go-zero/core/logx"
)

type MusicMd5ExistLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
	musicDomain *domain.MusicDomain
}

func NewMusicMd5ExistLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MusicMd5ExistLogic {
	return &MusicMd5ExistLogic{
		ctx:         ctx,
		svcCtx:      svcCtx,
		Logger:      logx.WithContext(ctx),
		musicDomain: domain.NewMusicDomain(*svcCtx.ChenDb),
	}
}

func (l *MusicMd5ExistLogic) MusicMd5Exist(in *music.MusicMd5ExeistReq) (*music.MusicMd5ExeistResp, error) {
	m, err := l.musicDomain.MusicMd5Exist(in.Md5)
	if err != nil {
		return nil, err
	}
	if m == nil {
		return &music.MusicMd5ExeistResp{Domain: ""}, nil
	}

	return &music.MusicMd5ExeistResp{
		Path:    m.Path,
		Md5:     m.Md5,
		Domain:  l.svcCtx.Config.GoFast.DNS,
		Pictrue: m.Pictrue,
		Size:    m.Size,
	}, nil
}
